<template>
    <div class="pointRules">
        <el-form :inline="true" :model="searchForm" class="demo-form-inline">
            <el-form-item label="适用角色：">
                <el-select v-model="searchForm.payForRole" filterable>
                    <el-option label="全部" :value="undefined"></el-option>
                    <el-option label="职业经纪人" :value="0"></el-option>
                    <el-option label="网络推客" :value="1"></el-option>
                    <el-option label="自来客" :value="2"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="节点规则名称：">
                <el-input v-model="searchForm.nodeRuleName"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="success" @click="searchList" id="monitorEnter">查询</el-button>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="fn('add')">新增</el-button>
            </el-form-item>
        </el-form>
        <el-table :data="tableData">
            <el-table-column type="index" label="序号" width="50"></el-table-column>
            <el-table-column prop="payForRole" label="适用角色">
                <template slot-scope="scope">
                    {{scope.row.payForRole==0?'职业经纪人':''}}
                    {{scope.row.payForRole==1?'网络推客':''}}
                    {{scope.row.payForRole==2?'自来客':''}}
                </template>
            </el-table-column>
            <el-table-column prop="nodeRuleName" label="节点规则名称"></el-table-column>
            <el-table-column prop="developerNodesMap.node1" label="开发商节点">
                <template slot-scope="scope">
                    {{Object.values(scope.row.developerNodesMap).join(',')}}
                </template>
            </el-table-column>
            <el-table-column label="跟进节点">
                <el-table-column v-for="item in specialColumn.brokerageLength" :key="item" :prop="'brokerageNodesMap.node'+item" :label="'节点'+item"></el-table-column>
            </el-table-column>
            <el-table-column label="经纪人奖励节点">
                <el-table-column v-for="item in specialColumn.awardsLength" :key="item" :prop="'awardsNodesMap.node'+item" :label="'节点'+item"></el-table-column>
            </el-table-column>
            <el-table-column prop="operatorName" label="操作人"></el-table-column>
            <el-table-column prop="updateTime" label="操作时间" min-width="100"></el-table-column>
            <el-table-column prop="" label="操作">
                <template slot-scope="scope">
                    <el-button type="text" @click="fn('edit',scope.row.id,scope.row.brokerageCount)">编辑</el-button>
                    <el-button type="text" @click="fn('delete',scope.row.id)" :disabled="scope.row.brokerageCount>0">删除</el-button>
                </template>
            </el-table-column>
            <el-table-column prop="brokerageCount" label="关联结佣套餐" align="center">
                <template slot-scope="scope">
                    {{scope.row.brokerageCount==0?0:''}}
                    <router-link v-show="scope.row.brokerageCount>0" :to="{path: '/brokerageRuleList', query: {nodeName: scope.row.nodeRuleName}}">{{scope.row.brokerageCount}}</router-link>
                </template>
            </el-table-column>
        </el-table>
        <div class="pagebar">
            <el-pagination
                background
                layout="total, sizes, prev, pager, next"
                :current-page.sync="currentPage"
                :page-sizes="[10, 20, 30, 40]"
                :page-size="pageSize"
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :total="totalSize">
            </el-pagination>
        </div>
    </div>
</template>

<script>
import api from "@/api/apiPath"

export default {
    name:"pointRules",
    title:"节点规则管理",
    created() {
        this.searchList()
    },
    activated(){
        this.searchList()
    },
    mounted() {
    },
    components: {},
    data() {
        return {
            searchForm: {
                payForRole: undefined,
                nodeRuleName: undefined
            },
            specialColumn: {
                brokerageLength:0,
                awardsLength:0
            },
            tableData:[],
            currentPage: 1,
            pageSize: 10,
            totalSize: 0 
        }
    },
    methods: {
        searchList () {
            let param = {}
            param.pageNum = this.currentPage
            param.pageSize = this.pageSize
            param.payForRole = this.searchForm.payForRole
            param.nodeRuleName = this.searchForm.nodeRuleName
            param.id = this.$route.query.nodeId
            this.axios.post(api.nodeRuleList, param).then(res => {
                this.tableData = res.data.data.responseDate
                this.totalSize = res.data.data.count
                this.specialColumn = res.data.data.maxLen
            })
        },
        // 分页器改变页码
        handleCurrentChange () {
            this.searchList()
        },
        handleSizeChange (val) {
            this.pageSize = val
            this.searchList()
        },
        fn(type,id,brokerageCount){
            if(type=='add'){
                this.$router.push({path: '/operatePointRules', query:{type: 'add'}})
            } else if (type == 'delete'){
                this.$confirm('是否确定删除该条规则?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    this.axios.post(api.nodeRuleDel,{id}).then(res =>{
                        this.$message.success('删除成功')
                        this.searchList()
                    })
                }).catch(() => {        
                });
            } else if (type == 'edit') {
                this.$router.push({path: '/operatePointRules', query: {type: 'edit', id: id,brokerageCount:brokerageCount}})
            }
        }
    },
    computed: {}
}
</script>
<style lang="stylus" scoped>
    .pointRules {
        
    }
</style>